package com.jiazhong.basic.pack0308.ex;

import java.util.InputMismatchException;

// finally
public class DemoC {

    private static void a() {
        // num:0 1 2
        int num = 0;
        System.out.println("随机数是：" + num);
        int result;
        try {
            // 书写的是可能出现异常的代码块
            result = 8 / num; // 数学异常
        } catch (InputMismatchException e) { // 处理方案是输入异常方案
            System.out.println("除数不能为0");
            result = 1;
        } finally {
            System.out.println("这段代码不管发生什么事情，都会执行");
        }
        System.out.println("计算的结果是：" + result);
    }


    private static int b() {
        int a = 9;
        try {
            return a;
        } finally {
            return 7;
        }
    }

    private static int c() {
        int a = 4;
        try {
            a++;
        } finally {
            a = 1;
        }
        return a;
    }

    private static int d() {
        int a = 1;
        try {
            a++; // 2
            return a;
        } finally {
            a++; // 3
            return a;
        }
    }

    public static void main(String[] args) {
        int b = d();
        System.out.println(b);
    }
}
